import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
import java.util.TimerTask;

class MyButton extends JButton
{
	private int[] coords = new int[2];
	private boolean isOccupied = false;
	private boolean isBlocked = false;
	
	public MyButton(String title)
	{
		super(title);
	}
	
	public MyButton()
	{
		super();
	}
	
	public void setCoords(int x, int y)
	{
		coords[0] = x;
		coords[1] = y;
	}
	
	public boolean isBlocked()
	{
		return isBlocked;
	}
	
	public void block()
	{
		isBlocked = true;
	}
	
	public void occupy()
	{
		if (!isOccupied)
		{
			this.setBackground(Color.black);
			isOccupied = true;
		}
		else
		{
			this.setBackground(null);
			isOccupied = false;
		}
	}
	
	public int[] getCoords()
	{
		return coords;
	}
	
	public boolean isOccupied()
	{
		return isOccupied;
	}
	
	public void red()
	{	
		Timer timer = new Timer();
		MyButton btn = this;
		Color color = btn.getBackground();
		btn.setBackground(Color.red);
		
		timer.schedule(new TimerTask() 
		{
			@Override
			public void run() 
			{
				btn.setBackground(color);
			}
		}, 500);
	}
	
	public void grey()
	{
		this.setBackground(Color.gray);
		this.block();
	}
	
	public void blue()
	{
		setBackground(Color.blue);
		this.block();
	}

	public void removeAL()
	{
		MyButton btn = this;
		
		for(ActionListener al : btn.getActionListeners()) 
		{
			btn.removeActionListener(al);
		}
	}
}